﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UCS.XNA.Draughts.Boards;
using UCS.XNA.Draughts.People;
using UCS.XNA.Draughts.Pieces;
using UCS.XNA.Utils;

namespace UCS.XNA.Draughts.GameStates
{
    public class EndGameState : IGameState
    {
        #region Private Members

        private Board _board;
        private Player _winner;
        private SpriteFont _font;

        #endregion

        #region Constructors

        public EndGameState(Board board, Player winner)
        {
            _board = board;
            _winner = winner;

            this.InitializeFont();
        }

        #endregion

        #region Private Methods

        private void DrawWinner()
        {
            if (this._winner == null)
                return;

            string text = this._winner.Color == PieceColor.Black ? "Pretos Venceram!" : "Brancos Venceram!";
            Color color = this._winner.Color == PieceColor.Black ? Color.Black : Color.White;
            GameResources.SpriteBatch.Begin();
            GameResources.SpriteBatch.DrawString(this._font, text, new Vector2(500, 50), color);
            GameResources.SpriteBatch.End();
        }

        private void InitializeFont()
        {
            this._font = GameResources.Content.Load<SpriteFont>("Arial");
        }

        #endregion

        #region Public Methods

        public void Update(GameTime gameTime)
        {
            _board.Update(gameTime);
        }

        public void Draw(GameTime gameTime)
        {
            _board.Draw(gameTime);
            this.DrawWinner();
        }

        public event EventHandler Ended;

        #endregion
    }
}
